package org.example.project.bookstore.listener;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.example.bean.RocketMQOrder;
import org.example.bean.wuliu;
import org.example.project.bookstore.service.wuliuService;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * @Auther:Liu
 * @Testname:OrderSuccessLogisticsLinstener
 * @Date:2025/8/27 10:09
 */
@Component
@Slf4j
@RocketMQMessageListener(consumerGroup = "order_success_1",topic = "order",selectorExpression = "transaction",messageModel = MessageModel.BROADCASTING)
public class OrderSuccessLogisticsLinstener implements RocketMQListener<String> {
    @Resource
    private wuliuService wuliuService;
    @Override
    public void onMessage(String s) {
        log.info("开始执行成功操作,开始发物流");
        RocketMQOrder rocketMQOrder = JSON.parseObject(s, RocketMQOrder.class);
        log.info("rocketMQOrder数据为:{}",rocketMQOrder);
        wuliu wuliu = new wuliu();
        wuliu.setOrderId(rocketMQOrder.getOrderId());
        log.info("rocketMQOrder.getLogisticsId():{}",rocketMQOrder.getLogisticsId());
        wuliu.setLogisticsId(rocketMQOrder.getLogisticsId());
        wuliuService.save(wuliu);
    }
}
